package day06;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class CalTotalAvg {
    public static void main(String[] args) {
      double[] scores = inputDate(6);
      double avg = calAvg(scores);
        System.out.println("平均分为："+avg);

    }
    public static double[] inputDate(int n){
        double[] scores = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i=0;i<scores.length;i++){
            System.out.println("请输入第"+(i+1)+"评委的分数");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }
    public static double calAvg(double[] scores){
        /*Arrays.sort(scores);
        double sum = 0,avg = 0;
        for(int i=1;i<scores.length-1;i++){
            sum+=scores[i];
        }
        avg=sum/(scores.length-2);
        return avg;
         */
        double total = 0.0;  //总分
        double max = scores[0];  //假设第一个元素为最高分
        double min = scores[0];  //假设第一个元素为最低分
        for (int i=0;i< scores.length;i++){
            total+=scores[i];  //累加所有评分
            if(scores[i]>max){  //找最高分
                max = scores[i];
            }
            if (scores[i]<min){  //找最低分
                min = scores[i];
            }
        }
        //计算平均分---总分减掉最高分和最低分之后，再除以(评委-2)
        double avg = (total-max-min)/(scores.length-2);
        return avg;
    }
}
